﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GeneratorLib.DB;
using GeneratorLib.DB.Connectios;
using GeneratorLib.DB.Schemas;


namespace Generator
{
    public partial class DBConnecter : Form
    {
        public DBConnecter()
        {
            InitializeComponent();
        }

        private IConnection _connectionInfo;
        public IConnection ConnectionInfo
        {
            get
            {
                _connectionInfo.SetName(txtName.Text);
                _connectionInfo.SetConnectStr(txtConnectStr.Text);
                return _connectionInfo;
            }
            set
            {
                _connectionInfo = value;
                txtName.Text = _connectionInfo.Name;
                txtConnectStr.Text = _connectionInfo.ConnectStr;
            }
        }

        private void btOK_Click(object sender, EventArgs e)
        {
            txtName.BackColor = Color.White;
            txtConnectStr.BackColor = Color.White;

            if (txtName.Text.Trim().Length == 0)
            {
                txtName.BackColor = Color.LightYellow;
                return;
            }

            if (txtConnectStr.Text.Trim().Length == 0)
            {
                txtConnectStr.BackColor = Color.LightYellow;
                return;
            }

            this.DialogResult = DialogResult.OK;
            this.Close();

        }


    }   

}
